<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
  
  var countBadPairs = function (nums) {
      const c = n => n * (n - 1) / 2, n = nums.length, map = new Map()
      let ans = c(n)
      for (let i = 0; i < n; i++)
        map.set(nums[i] - i, (map.get(nums[i] - i) || 0) + 1)

      for (let [k, v] of map)
        ans -= c(v)
      return ans
    };

  </script>
</body>
</html>